package com.itheima.health.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.health.dao.MemberDao;
import com.itheima.health.dao.OrderDao;
import com.itheima.health.service.ReportService;
import com.itheima.health.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @autahor: csl
 * @date: 2019/7/28
 * @description:
 * @version:1.0
 */
@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private MemberDao memberDao;
    @Autowired
    private OrderDao orderDao;
    @Override
    public List<Integer> findMemberCountByMonthList(List<String> monthList) {
        List<Integer>memberCountList=new ArrayList<>();
        for (String month : monthList) {
           Integer currMemberCount= memberDao.findMemberCountByBeforeDate(month+".31");
           memberCountList.add(currMemberCount);
        }
        return memberCountList;
    }

    @Override
    public List<Map<String, Object>> findSetmealCount() {

        return orderDao.findSetmealCount();
    }

    @Override
    public Map<String, Object> getBussinessReport() {
         try {
          //获取今天日期
             String today = DateUtils.parseDate2String(DateUtils.getToday());
             //获取本周周一日期
             String weekMonday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
             //获取本月第一天日期
             String firstDayInMonth = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
             //=============
             //获取会员相关数据
          Integer todayMember=   memberDao.findMemberCountByDate(today);
          Integer thisWeekNewMember= memberDao.findMemberCountByAfterDate(weekMonday);
          Integer thisMonthNewMember=memberDao.findMemberCountByAfterDate(firstDayInMonth);
          Integer totalMember=memberDao.findMemberTotalCount();
          //===============
          //===============
          //获取预约相关数据
             Integer todayOrderNumber=orderDao.findOrderCountByDate(today);
             Integer thisWeekOrderNumber=orderDao.findOrderCountByAfter(weekMonday);
             Integer thisMonthOrderNumber=orderDao.findOrderCountByAfter(firstDayInMonth);
             //获取到诊相关数据
             Integer todayVisitNumber=orderDao.findVisitsCountByDate(today);
             Integer weekVisitNumber=orderDao.findVisitsCountByAfterDate(weekMonday);
             Integer monthVisitNumber=orderDao.findVisitsCountByAfterDate(firstDayInMonth);
          //===============
          //===============
          //获取热门套餐
             List<Map>hostSetmeal=orderDao.findHostSetmeal();
          //===============
             Map<String,Object> result=new HashMap<>();
             result.put("reportDate",today);
             // 会员人数相关数据
             result.put("todayNewMember",todayMember);
             result.put("thisWeekNewMember",thisWeekNewMember);
             result.put("thisMonthNewMember",thisMonthNewMember);
             result.put("totalMember",totalMember);
             // 预约人数相关数据
             result.put("todayOrderNumber",todayOrderNumber);
             result.put("thisWeekOrderNumber",thisWeekOrderNumber);
             result.put("thisMonthOrderNumber",thisMonthOrderNumber);
             // 到诊人数相关数据
             result.put("todayVisitsNumber",todayVisitNumber);
             result.put("thisWeekVisitsNumber",weekVisitNumber);
             result.put("thisMonthVisitsNumber",monthVisitNumber);
             // 套餐热门数据
             result.put("hotSetmeal",hostSetmeal);
             return result;
         }catch (Exception e){
                     e.printStackTrace();
                 }
        return null;
    }
}
